import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;


public class SocketCaller {
	
	final private static int TIMEOUT = 5000;
	
    public static void main(String[] args) throws IOException {
    	System.out.println("Starting Caller");
    	//get subnet mask
    	//System.setProperty("java.net.preferIPv4Stack", "true");
    	CallerThread caller;
    	InetAddress localHost = Inet4Address.getLocalHost();

    	byte[] localBytes = localHost.getAddress();
    	
    	//main loop
    	for (int i =2; i<10; i++){
    		InetAddress host = InetAddress.getByAddress(new byte[]{
    				localBytes[0],
    				localBytes[1],
    				localBytes[2],
    				(new Integer(i)).byteValue()
    		}
    		);

    		if(host.isReachable(TIMEOUT)){
    			System.out.println("Host address: " +host.getHostAddress()+" is reachable");
    			caller = new CallerThread(host);
    			caller.start();
    		}
    		else {
    			System.out.println("Host address: " +host.getHostAddress()+" is not reachable");
    		}
    		
    		
    	}
    	System.out.println("End");
    }
    
    
}
